package com.scuec.tourismwebsite.mapper;

import com.scuec.tourismwebsite.entity.FreeformPostLike;
import com.scuec.tourismwebsite.entity.PostLike;
import com.scuec.tourismwebsite.vo.OfficialLike;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FreeformPostLikeMapper {
    @Update("INSERT INTO freeform_post_like (post_id, user_id) VALUES (#{post_id}, #{user_id});")
    public int insertFreeformPostLike(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Select("SELECT * FROM freeform_post_like where user_id=#{user_id} and post_id=#{post_id}")
    public List<FreeformPostLike> selectFreeformPostLikeById(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Delete("DELETE FROM freeform_post_like where user_id=#{user_id} and post_id=#{post_id}")
    public int deleteFreeformPostLike(@Param("user_id") int user_id, @Param("post_id") int post_id);

    @Select({
            "SELECT ",
            "   l.like_id, ",
            "   l.post_id, ",
            "   l.user_id, ",
            "   l.like_date, ",
            "   p.title, ",
            "   p.content, ",
            "   p.image_1, ",
            "   p.category, ",
            "   p.post_date, ",
            "   p.views_count, ",
            "   p.likes_count, ",
            "   p.comments_count ",
            "FROM ",
            "   freeform_post_like l ",
            "JOIN ",
            "   freeform_post p ON l.post_id = p.post_id ",
            "WHERE ",
            "   l.user_id = #{user_id}  "
    })
    List<OfficialLike> selectOfficialLikesByUserId(@Param("user_id") int user_id);
}
